package com.web.common.dataDictionary.PO;

import java.util.*;
import com.css.sword.kernel.base.annotation.*;
import com.css.sword.kernel.base.dataElement.*;
import com.css.sword.kernel.base.exception.SwordBaseCheckedException;

import com.web.common.dataDictionary.DE.DE_ALIPAYID;
import com.web.common.dataDictionary.DE.DE_WEBUSERNAME;
import com.web.common.dataDictionary.DE.DE_ORDERNO;
import com.web.common.dataDictionary.DE.DE_GOODSCATEGORYID;
import com.web.common.dataDictionary.DE.DE_GOODSID;
import com.web.common.dataDictionary.DE.DE_GMSJ;
import com.web.common.dataDictionary.DE.DE_GMZT;
import com.web.common.dataDictionary.DE.DE_BZ;


/**
 * 用户购买表
 */
@PersistObject
public class TabUserbuyPO extends AbsPersistObject {
	//private static final long serialVersionUID = 9023198034992820614L;
	private static final long serialVersionUID = 1L;
	private static final Map<String, Integer> fieldIndex = new HashMap<String, Integer>(8);
	private static final BitSet HAS_DEFAULT_VALUE = new BitSet(8);
	
	static{
		fieldIndex.put("alipayid",0);fieldIndex.put("webusername",1);fieldIndex.put("orderno",2);fieldIndex.put("goodscategoryid",3);fieldIndex.put("goodsid",4);fieldIndex.put("gmsj",5);fieldIndex.put("gmzt",6);fieldIndex.put("bz",7);
	}
	
	/**
	 * 物理表名
	 */
	public static final String TABLE_NAME = "tab_userbuy";

	/**
	 * 支付宝交易号
	 */
	private DE_ALIPAYID alipayid = DE_ALIPAYID.getTemplateInstance();

	/**
	 * 用户名
	 */
	private DE_WEBUSERNAME webusername = DE_WEBUSERNAME.getTemplateInstance();

	/**
	 * 订单号
	 */
	private DE_ORDERNO orderno = DE_ORDERNO.getTemplateInstance();

	/**
	 * 商品分类id
	 */
	private DE_GOODSCATEGORYID goodscategoryid = DE_GOODSCATEGORYID.getTemplateInstance();

	/**
	 * 商品id
	 */
	private DE_GOODSID goodsid = DE_GOODSID.getTemplateInstance();

	/**
	 * 购买时间
	 */
	private DE_GMSJ gmsj = DE_GMSJ.getTemplateInstance();

	/**
	 * 购买状态
	 */
	private DE_GMZT gmzt = DE_GMZT.getTemplateInstance();

	/**
	 * 备注
	 */
	private DE_BZ bz = DE_BZ.getTemplateInstance();


	public TabUserbuyPO(){
		this.insertState = new BitSet(8);
		this.updateState = new BitSet(8);
	}

	
	/**
	 * 获取 "支付宝交易号" 值
	 */	
	public DE_ALIPAYID getAlipayid(){
		return  alipayid;
	}
	
	/**
	 * 设置 "支付宝交易号" 值
	 */
	public void setAlipayid(DE_ALIPAYID alipayid) {
		if(alipayid == null){
			alipayid= DE_ALIPAYID.getTemplateInstance();
		}
		recordChangeFlag(0);
		this.alipayid = alipayid;
	}
	
	/**
	 * 获取 "用户名" 值
	 */	
	public DE_WEBUSERNAME getWebusername(){
		return  webusername;
	}
	
	/**
	 * 设置 "用户名" 值
	 */
	public void setWebusername(DE_WEBUSERNAME webusername) {
		if(webusername == null){
			webusername= DE_WEBUSERNAME.getTemplateInstance();
		}
		recordChangeFlag(1);
		this.webusername = webusername;
	}
	
	/**
	 * 获取 "订单号" 值
	 */	
	public DE_ORDERNO getOrderno(){
		return  orderno;
	}
	
	/**
	 * 设置 "订单号" 值
	 */
	public void setOrderno(DE_ORDERNO orderno) {
		if(orderno == null){
			orderno= DE_ORDERNO.getTemplateInstance();
		}
		recordChangeFlag(2);
		this.orderno = orderno;
	}
	
	/**
	 * 获取 "商品分类id" 值
	 */	
	public DE_GOODSCATEGORYID getGoodscategoryid(){
		return  goodscategoryid;
	}
	
	/**
	 * 设置 "商品分类id" 值
	 */
	public void setGoodscategoryid(DE_GOODSCATEGORYID goodscategoryid) {
		if(goodscategoryid == null){
			goodscategoryid= DE_GOODSCATEGORYID.getTemplateInstance();
		}
		recordChangeFlag(3);
		this.goodscategoryid = goodscategoryid;
	}
	
	/**
	 * 获取 "商品id" 值
	 */	
	public DE_GOODSID getGoodsid(){
		return  goodsid;
	}
	
	/**
	 * 设置 "商品id" 值
	 */
	public void setGoodsid(DE_GOODSID goodsid) {
		if(goodsid == null){
			goodsid= DE_GOODSID.getTemplateInstance();
		}
		recordChangeFlag(4);
		this.goodsid = goodsid;
	}
	
	/**
	 * 获取 "购买时间" 值
	 */	
	public DE_GMSJ getGmsj(){
		return  gmsj;
	}
	
	/**
	 * 设置 "购买时间" 值
	 */
	public void setGmsj(DE_GMSJ gmsj) {
		if(gmsj == null){
			gmsj= DE_GMSJ.getTemplateInstance();
		}
		recordChangeFlag(5);
		this.gmsj = gmsj;
	}
	
	/**
	 * 获取 "购买状态" 值
	 */	
	public DE_GMZT getGmzt(){
		return  gmzt;
	}
	
	/**
	 * 设置 "购买状态" 值
	 */
	public void setGmzt(DE_GMZT gmzt) {
		if(gmzt == null){
			gmzt= DE_GMZT.getTemplateInstance();
		}
		recordChangeFlag(6);
		this.gmzt = gmzt;
	}
	
	/**
	 * 获取 "备注" 值
	 */	
	public DE_BZ getBz(){
		return  bz;
	}
	
	/**
	 * 设置 "备注" 值
	 */
	public void setBz(DE_BZ bz) {
		if(bz == null){
			bz= DE_BZ.getTemplateInstance();
		}
		recordChangeFlag(7);
		this.bz = bz;
	}


	@Override
	public BaseDataElement<?>[] fields(){
		return new BaseDataElement<?>[] {alipayid,webusername,orderno,goodscategoryid,goodsid,gmsj,gmzt,bz};
	}
	
	@Override
	public String[] fieldNames() {
		return new String[]{"alipayid","webusername","orderno","goodscategoryid","goodsid","gmsj","gmzt","bz"};
	}
	
	@Override
	public BaseDataElement<?> getFieldValue(String fieldName)  {
		final Integer index = fieldIndex.get(fieldName);
		if (index == null) {
			throw new IllegalArgumentException("PO对象中没有" + fieldName + "字段");
		}
		switch (index) {
		case 0 : return alipayid;
		case 1 : return webusername;
		case 2 : return orderno;
		case 3 : return goodscategoryid;
		case 4 : return goodsid;
		case 5 : return gmsj;
		case 6 : return gmzt;
		case 7 : return bz;
 
		default:
			throw new IllegalArgumentException("PO对象中没有" + fieldName + "字段");
		}
	}
	
	@Override
	public TabUserbuyPO setFieldValue(String fieldName, Object fieldValue) throws SwordBaseCheckedException {
		if (fieldValue != null && !(fieldValue instanceof BaseDataElement<?>)) {
			throw new SwordBaseCheckedException("字段值类型不是DataElelement子类型");
		}

		final Integer index = fieldIndex.get(fieldName);
		if (index == null) {
			throw new SwordBaseCheckedException("PO对象中没有" + fieldName + "字段");
		}

		switch (index) {

				case 0 : {
					if (fieldValue == null) {
						setAlipayid(null);
					} else {
						setAlipayid((DE_ALIPAYID) fieldValue);
					}
					return this;
				}
				
				case 1 : {
					if (fieldValue == null) {
						setWebusername(null);
					} else {
						setWebusername((DE_WEBUSERNAME) fieldValue);
					}
					return this;
				}
				
				case 2 : {
					if (fieldValue == null) {
						setOrderno(null);
					} else {
						setOrderno((DE_ORDERNO) fieldValue);
					}
					return this;
				}
				
				case 3 : {
					if (fieldValue == null) {
						setGoodscategoryid(null);
					} else {
						setGoodscategoryid((DE_GOODSCATEGORYID) fieldValue);
					}
					return this;
				}
				
				case 4 : {
					if (fieldValue == null) {
						setGoodsid(null);
					} else {
						setGoodsid((DE_GOODSID) fieldValue);
					}
					return this;
				}
				
				case 5 : {
					if (fieldValue == null) {
						setGmsj(null);
					} else {
						setGmsj((DE_GMSJ) fieldValue);
					}
					return this;
				}
				
				case 6 : {
					if (fieldValue == null) {
						setGmzt(null);
					} else {
						setGmzt((DE_GMZT) fieldValue);
					}
					return this;
				}
				
				case 7 : {
					if (fieldValue == null) {
						setBz(null);
					} else {
						setBz((DE_BZ) fieldValue);
					}
					return this;
				}
				
		default:
			throw new SwordBaseCheckedException("PO对象中没有" + fieldName + "字段");
		}
	
	}

	@Override
	protected TabUserbuyPO clone() {
		TabUserbuyPO t = new TabUserbuyPO();
		
		t.setAlipayid(this.alipayid);
		t.setWebusername(this.webusername);
		t.setOrderno(this.orderno);
		t.setGoodscategoryid(this.goodscategoryid);
		t.setGoodsid(this.goodsid);
		t.setGmsj(this.gmsj);
		t.setGmzt(this.gmzt);
		t.setBz(this.bz);

		return t;
	}

	@Override
	public TabUserbuyPO loadMap(Map<String, Object> dataMap) throws SwordBaseCheckedException {
		Object value = null;

		if(dataMap.containsKey("alipayid")){
			value = dataMap.get("alipayid");
			
			if (value == null) {
				this.setAlipayid(null);
			} else {
				if (value instanceof DE_ALIPAYID) {
					this.setAlipayid((DE_ALIPAYID) value);
				}
			    else {
					this.setAlipayid(new DE_ALIPAYID(value.toString()));
				}
			}
		}

		if(dataMap.containsKey("webusername")){
			value = dataMap.get("webusername");
			
			if (value == null) {
				this.setWebusername(null);
			} else {
				if (value instanceof DE_WEBUSERNAME) {
					this.setWebusername((DE_WEBUSERNAME) value);
				}
			    else {
					this.setWebusername(new DE_WEBUSERNAME(value.toString()));
				}
			}
		}

		if(dataMap.containsKey("orderno")){
			value = dataMap.get("orderno");
			
			if (value == null) {
				this.setOrderno(null);
			} else {
				if (value instanceof DE_ORDERNO) {
					this.setOrderno((DE_ORDERNO) value);
				}
			    else {
					this.setOrderno(new DE_ORDERNO(value.toString()));
				}
			}
		}

		if(dataMap.containsKey("goodscategoryid")){
			value = dataMap.get("goodscategoryid");
			
			if (value == null) {
				this.setGoodscategoryid(null);
			} else {
				if (value instanceof DE_GOODSCATEGORYID) {
					this.setGoodscategoryid((DE_GOODSCATEGORYID) value);
				}
			    else {
					this.setGoodscategoryid(new DE_GOODSCATEGORYID(value.toString()));
				}
			}
		}

		if(dataMap.containsKey("goodsid")){
			value = dataMap.get("goodsid");
			
			if (value == null) {
				this.setGoodsid(null);
			} else {
				if (value instanceof DE_GOODSID) {
					this.setGoodsid((DE_GOODSID) value);
				}
			    else {
					this.setGoodsid(new DE_GOODSID(value.toString()));
				}
			}
		}

		if(dataMap.containsKey("gmsj")){
			value = dataMap.get("gmsj");
			
			if (value == null) {
				this.setGmsj(null);
			} else {
				if (value instanceof DE_GMSJ) {
					this.setGmsj((DE_GMSJ) value);
				}
				else if(value instanceof java.util.Date){
					this.setGmsj(new DE_GMSJ((java.util.Date)value));
				}
			    else {
					this.setGmsj(new DE_GMSJ(value.toString()));
				}
			}
		}

		if(dataMap.containsKey("gmzt")){
			value = dataMap.get("gmzt");
			
			if (value == null) {
				this.setGmzt(null);
			} else {
				if (value instanceof DE_GMZT) {
					this.setGmzt((DE_GMZT) value);
				}
			    else {
					this.setGmzt(new DE_GMZT(value.toString()));
				}
			}
		}

		if(dataMap.containsKey("bz")){
			value = dataMap.get("bz");
			
			if (value == null) {
				this.setBz(null);
			} else {
				if (value instanceof DE_BZ) {
					this.setBz((DE_BZ) value);
				}
			    else {
					this.setBz(new DE_BZ(value.toString()));
				}
			}
		}

		return this;
	}
	
	@Override
	public Map<String,Object> toMap() {
		Map<String,Object> dataMap = new HashMap<String,Object>();

		dataMap.put("alipayid", alipayid);
		dataMap.put("webusername", webusername);
		dataMap.put("orderno", orderno);
		dataMap.put("goodscategoryid", goodscategoryid);
		dataMap.put("goodsid", goodsid);
		dataMap.put("gmsj", gmsj);
		dataMap.put("gmzt", gmzt);
		dataMap.put("bz", bz);
		
		return dataMap;
	}
	
	@Override
	public Map<String,Object> toMapWithDEValue() {
		Map<String,Object> dataMap = new HashMap<String,Object>();

		dataMap.put("alipayid", (alipayid==null?null:alipayid.value));
		dataMap.put("webusername", (webusername==null?null:webusername.value));
		dataMap.put("orderno", (orderno==null?null:orderno.value));
		dataMap.put("goodscategoryid", (goodscategoryid==null?null:goodscategoryid.value));
		dataMap.put("goodsid", (goodsid==null?null:goodsid.value));
		dataMap.put("gmsj", (gmsj==null?null:gmsj.value));
		dataMap.put("gmzt", (gmzt==null?null:gmzt.value));
		dataMap.put("bz", (bz==null?null:bz.value));
		
		return dataMap;
	}
	
	@Override
	public TabUserbuyPO newInstance() {
		return new TabUserbuyPO();
	}
	
	@Override
	public String getTableName(){
		return TABLE_NAME;
	}
	
	@Override
	public BaseDataElement<?>[] getPrimaryKey() {
		return new BaseDataElement<?>[]{orderno};
	}

	@Override
	public void checkNotNull(byte sqlType) throws SwordBaseCheckedException {
		StringBuilder errorMsg = new StringBuilder();
		// insert
		if (sqlType == 0) {
				//只校验不可为空但又没有默认值的字段
				if (orderno.value == null && !HAS_DEFAULT_VALUE.get(2)) {
					errorMsg.append("字段orderno不允许为空\n");
				}

		}
		// update
		else if (sqlType == 1) {
		if (updateState.get(2) && orderno.value == null) {
			errorMsg.append("字段orderno不允许为空\n");
		}

		}
		
		if (errorMsg.length() > 0) {
			errorMsg.setLength(errorMsg.length() - 1);
			throw new SwordBaseCheckedException(errorMsg.toString());
		}
	}

	@Override
	public void updateLrrq(DateDE lrrq) {
	}

	@Override
	public void updateXgrq(DateDE xgrq) {
	}

	@Override
	public String toString() {
		StringBuilder str = new StringBuilder();
		str.append("alipayid:").append(alipayid.value!=null?alipayid:"").append(" ").append("webusername:").append(webusername.value!=null?webusername:"").append(" ").append("orderno:").append(orderno.value!=null?orderno:"").append(" ").append("goodscategoryid:").append(goodscategoryid.value!=null?goodscategoryid:"").append(" ").append("goodsid:").append(goodsid.value!=null?goodsid:"").append(" ").append("gmsj:").append(gmsj.value!=null?gmsj:"").append(" ").append("gmzt:").append(gmzt.value!=null?gmzt:"").append(" ").append("bz:").append(bz.value!=null?bz:"").append(" ");
		return str.toString();
	}
	
}
